package com.zhucan.autoconfigure.swagger;

import org.springframework.boot.context.properties.ConfigurationProperties;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.ApiKey;
import springfox.documentation.service.Contact;

/**
 * @author: zhuCan
 * @date: 2020/6/12 13:48
 * @description:
 */
@ConfigurationProperties(prefix = "swagger")
public class SwaggerProperties {

  private String path;

  private String host;

  private String basePackageScan;

  private SwaggerApiKey apiKey;

  private SwaggerApiInfo apiInfo;

  private Boolean enable = true;

  static class SwaggerApiKey{
    private String name;
    private String keyName;
    private String passAs;

    public String getName() {
      return name;
    }

    public void setName(String name) {
      this.name = name;
    }

    public String getKeyName() {
      return keyName;
    }

    public void setKeyName(String keyName) {
      this.keyName = keyName;
    }

    public String getPassAs() {
      return passAs;
    }

    public void setPassAs(String passAs) {
      this.passAs = passAs;
    }
  }

  static class SwaggerApiInfo{
    private  String version = "1.0";
    private  String title = "Api Documentation";
    private  String description = "Api Documentation";
    private  String termsOfServiceUrl = "urn:tos";
    private  String license = "Apache 2.0";
    private  String licenseUrl = "http://www.apache.org/licenses/LICENSE-2.0";
    private  Contact contact = new Contact("", "", "");;

    public String getVersion() {
      return version;
    }

    public void setVersion(String version) {
      this.version = version;
    }

    public String getTitle() {
      return title;
    }

    public void setTitle(String title) {
      this.title = title;
    }

    public String getDescription() {
      return description;
    }

    public void setDescription(String description) {
      this.description = description;
    }

    public String getTermsOfServiceUrl() {
      return termsOfServiceUrl;
    }

    public void setTermsOfServiceUrl(String termsOfServiceUrl) {
      this.termsOfServiceUrl = termsOfServiceUrl;
    }

    public String getLicense() {
      return license;
    }

    public void setLicense(String license) {
      this.license = license;
    }

    public String getLicenseUrl() {
      return licenseUrl;
    }

    public void setLicenseUrl(String licenseUrl) {
      this.licenseUrl = licenseUrl;
    }

    public Contact getContact() {
      return contact;
    }

    public void setContact(Contact contact) {
      this.contact = contact;
    }
  }

  public String getPath() {
    return path;
  }

  public void setPath(String path) {
    this.path = path;
  }

  public String getHost() {
    return host;
  }

  public void setHost(String host) {
    this.host = host;
  }

  public String getBasePackageScan() {
    return basePackageScan;
  }

  public void setBasePackageScan(String basePackageScan) {
    this.basePackageScan = basePackageScan;
  }

  public SwaggerApiKey getApiKey() {
    return apiKey;
  }

  public void setApiKey(SwaggerApiKey apiKey) {
    this.apiKey = apiKey;
  }

  public SwaggerApiInfo getApiInfo() {
    return apiInfo;
  }

  public void setApiInfo(SwaggerApiInfo apiInfo) {
    this.apiInfo = apiInfo;
  }

  public Boolean getEnable() {
    return enable;
  }

  public void setEnable(Boolean enable) {
    this.enable = enable;
  }

  public ApiKey apiKey(){
    return new ApiKey(apiKey.name, apiKey.keyName, apiKey.passAs);
  }

  public ApiInfo apiInfo(){
    return new ApiInfoBuilder()
        .title(apiInfo.title)
        .description(apiInfo.description)
        .license(apiInfo.license)
        .licenseUrl(apiInfo.licenseUrl)
        .version(apiInfo.version)
        .build();
  }
}
